[ResourceTiming]: Abstract away common test preamble Tests in entry-attributes.html had a common setup preamble that could not be captured with WPT's setup() so was copy-pasted into each case. This change refactors the tests to rely on a helper that centralizes the common setup logic. Bug: 1171767 Change-Id: Id7164fddde4726888cb9c4f05958eac47398fdc9 GithubIssue: https://github.com/w3c/resource-timing/issues/254 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2733350 Commit-Queue: Tom McKee <tommckee@chromium.org> Reviewed-by: Yoav Weiss <yoavweiss@chromium.org> Cr-Commit-Position: refs/heads/master@{#861545} 
diff --git a/resource-timing/entry-attributes.html b/resource-timing/entry-attributes.html index 013f4d7..53cd113 100644 --- a/resource-timing/entry-attributes.html +++ b/resource-timing/entry-attributes.html 
@@ -93,31 +93,38 @@  ]);  }   -promise_test(async () => { - // Clear out everything that isn't the one ResourceTiming entry under test. - performance.clearResourceTimings(); - await load_image("resources/fake_responses.py#hash=1"); - const entry_list = performance.getEntriesByType("resource"); - if (entry_list.length != 1) { - throw new Error("There should be one entry for one resource"); - } - const entry = entry_list[0]; - assert_true(entry.name.includes('#hash=1'), - "There should be a hash in the resource name"); +// Given a resource-loader and a PerformanceResourceTiming validator, loads a +// resource and validates the resulting entry. +function attribute_test(load_resource, validate, test_label) { + promise_test( + async () => { + // Clear out everything that isn't the one ResourceTiming entry under test. + performance.clearResourceTimings();   - assert_http_resource(entry); -}, "Image resources should generate conformant entries"); + await load_resource();   -promise_test(async () => { - // Clear out everything that isn't the one ResourceTiming entry under test. - performance.clearResourceTimings(); - await load_font("/fonts/Ahem.ttf"); - const entry_list = performance.getEntriesByType("resource"); - if (entry_list.length != 1) { - throw new Error("There should be one entry for one resource"); - } - assert_http_resource(entry_list[0]); -}, "Font resources should generate conformant entries"); + const entry_list = performance.getEntriesByType("resource"); + if (entry_list.length != 1) { + throw new Error(`There should be one entry for one resource (found ${entry_list.length})`); + } + + validate(entry_list[0]); + }, test_label); +} + +attribute_test( + () => load_image("resources/fake_responses.py#hash=1"), + entry => { + assert_true(entry.name.includes('#hash=1'), + "There should be a hash in the resource name"); + assert_http_resource(entry); + }, + "Image resources should generate conformant entries"); + +attribute_test( + () => load_font("/fonts/Ahem.ttf"), + assert_http_resource, + "Font resources should generate conformant entries");    </script>  </head>